<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>后台主页</title>
  <script src="./jquery.js"></script>
</head>

<body>
  <h1>首页</h1>

  <button id="btnLogout">退出登录</button>

  <script>
    $.ajax({
      url: '/username',
      type: 'post',
      headers:{
        Authorization:'Bearer '+localStorage.getItem('token')
      },
      data: {},
      success: function (res) {
        console.log(res, 999)
      },
    })

    $("#btnLogout").on('click', function () {
      $.ajax({
        url: '/api/logout',
        type: 'get',
        data: {},
        success: function (res) {
          console.log(res, 999)
          if (res.code == 1) {
            location.href = './login.html'
          }

        },
      })
    })
  </script>
</body>

</html>